# coding:utf-8
from PySide6.QtCore import Qt, Signal
from PySide6.QtGui import QMouseEvent
from PySide6.QtWidgets import (QSlider)


class CustomSlider(QSlider):
    """ A slider can be clicked """

    clicked = Signal(int)

    def __init__(self, orientation, parent=None):
        super().__init__(orientation, parent=parent)

    def mousePressEvent(self, e: QMouseEvent):
        super().mousePressEvent(e)

        if self.orientation() == Qt.Orientation.Horizontal:
            value = int(e.pos().x() / self.width() * self.maximum())
        else:
            value = int((self.height() - e.pos().y()) /
                        self.height() * self.maximum())

        self.setValue(value)
        self.clicked.emit(self.value())
